package com.hngy.xpq.android_service;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImageButton play = findViewById(R.id.service_dijia);
        play.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (YYService.plays == false){
                    startService(new Intent(MainActivity.this,YYService.class));
                    ((ImageButton) v).setImageDrawable(getResources().getDrawable(R.drawable.play,null));
                } else {
                    stopService(new Intent(MainActivity.this,YYService.class));
                    ((ImageButton) v).setImageDrawable(getResources().getDrawable(R.drawable.stop,null));
                }
            }
        });
    }

    @Override
    protected void onStart() {
        startService(new Intent(MainActivity.this,YYService.class));
        super.onStart();
    }
}